import java.io.*;
import java.util.ArrayList;
import java.util.Random;

public class SumOfRandomNumbers {
    Random rand = new Random(); // 随机数生成器
    int sum = 0; // 用于存储100个随机数的和


    public  ArrayList<Integer> numList() throws IOException {
        ArrayList<Integer> list =new ArrayList<Integer>();
        for (int i = 0; i < 100; i++) {
            int randomNumber = rand.nextInt(100); // 生成0到99之间的随机整数
            list.add(randomNumber);
            sum += randomNumber; // 将这个随机整数加入到总和中

        }
        try (PrintWriter writer = new PrintWriter(new FileWriter("./sum/sum.txt"))) {
         // 写入数字到文件中
            writer.println(sum);
        } catch (IOException e) {
            System.out.println("写入文件时出错：" + e.getMessage());
        }
        return list;
    }



}
